<?php View::render('admin/layouts/meta'); ?>
<script charset="utf-8" src="https://api.map.baidu.com/api?v=2.0&ak=<?php echo Configure::get('baidu.ak');?>"></script>
<body>
<div class="page-container">
    <form>
        <div class="text-c">
            <input type="text" class="input-text" style="width:120px" id="address" placeholder="地理位置搜索" name="address" value="">
            <button type="button" class="btn btn-default radius"  id="j_soso" name=""><i class="Hui-iconfont">&#xe665;</i></button>
            <input type="text" class="input-text" style="width:80px" id="x" placeholder="经度" name="lng" value="<?php echo $lng;?>">
            <input type="text" class="input-text" style="width:80px" id="y" placeholder="纬度" name="lat" value="<?php echo $lat;?>">
            <button type="button" class="btn btn-success radius j_submit">确认提交</button>
            <span>点击地图选择门店地址</span>
        </div>
    </form>
	<div class="mt-20" style="width:100%;height:400px;" id="allmap"></div>
</div>
</body>
<?php View::render('admin/layouts/footer'); ?>
<script type="text/javascript">
$(function(){
    var city='上海市',
    x=parseFloat($('#x').attr('value')),
    y=parseFloat($('#y').attr('value'));
    map = new BMap.Map("allmap");
    map.addControl(new BMap.NavigationControl());
    map.enableScrollWheelZoom();
    map.enableContinuousZoom();
    console.log(x);
    if(x!=0&&y!=0) {
            var point = new BMap.Point(x,y);
            map.centerAndZoom(point, 14);
            var marker = new BMap.Marker(point);
            map.addOverlay(marker);
    }else{
            map.centerAndZoom(city, 12);
    }
    //单击事件
    function showInfo(e){
        map.clearOverlays();
        x=e.point.lng;
        y=e.point.lat
        var point = new BMap.Point(x,y);
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
        $("#x").attr('value', x);
        $("#y").attr('value', y);
    }
    map.addEventListener("click", showInfo);
    $(".j_submit").click(function(){
        if(!x||!y){
            alert('请设置好坐标点后点确定');
            return false;
        }
        $(parent.document.getElementById('lng')).attr('value', x);
        $(parent.document.getElementById('lat')).attr('value', y);
        var index = parent.layer.getFrameIndex(window.name); 
        parent.layer.close(index); 
    });
    $("#j_soso").click(function(){
        var address = $("#address").val();
        if(!address) {
            alert('请填写地址再搜索');
        }
        var local = new BMap.LocalSearch(map, {
            renderOptions:{map: map}
        });
        local.search(address);
        return false;
    });
});
</script>
</html>